<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
  function cook(){
    console.log('开始做饭')
    var p = new Promise(function(resolve,reject){
      setTimeout(function(){
        console.log('做饭完毕')
        resolve('鸡蛋炒饭')
      },1000)
    })
    return p
  }

  // 吃饭
  function eat(data){
    console.log('开始吃饭'+ data)
    var p = new Promise(function(resolve,reject){
      setTimeout(function(){
        console.log('吃饭完毕')
        resolve('碗和筷子')
      }, 1000);
    })
    return p;
  }

  cook()
  .then(function(data) {
    throw new Error('米饭被打翻了')
    eat(data);
  })
  .catch(data=>{
    console.log(data)
  })
</script>
</html>